version 10.1
	
	/************************/
	/* The loglikelihood.	*/
	/************************/


program define warofatt_llf

	version 9
	args lnf theta1 theta2 theta3 theta4 theta5

	tempvar lambda_W lambda_SS p_W pi_SS p_SS wblden_W wblcum_W wblden_SS dens_mix

	quietly gen double `lambda_W'	= exp(`theta1')
	quietly gen double `lambda_SS'	= exp(`theta2')
	quietly gen double `pi_SS'	= exp(`theta3')/(1+exp(`theta3'))
	quietly gen double `p_W' 	= exp(`theta4')
	quietly gen double `p_SS' 	= exp(`theta5')

	quietly gen double `wblden_W'	= `lambda_W'*`p_W'*((`lambda_W'*$ML_y1)^(`p_W'-1))*exp(-(`lambda_W'*$ML_y1)^`p_W')
	quietly gen double `wblcum_W'	= 1 - exp(-(`lambda_W'*$ML_y2)^`p_W')
	quietly gen double `wblden_SS'	= `lambda_SS'*`p_SS'*((`lambda_SS'*$ML_y1)^(`p_SS'-1))*exp(-(`lambda_SS'*$ML_y1)^`p_SS')

	quietly gen double `dens_mix' 	= `pi_SS'*(`wblden_SS') + (1-`pi_SS')*(`wblden_W'/`wblcum_W')

	quietly replace `lnf' = ln(`dens_mix') if $ML_y1 <= $ML_y2
	quietly replace `lnf' = ln(`wblden_SS') + ln(`pi_SS') if $ML_y1 > $ML_y2

end

